﻿#include "ConfigManager.h"

bool ConfigManager::LoadConfig(const std::string& filepath)
{
	SPDLOG_INFO("配置文件解析...");
	pugi::xml_document doc;
	auto ret = doc.load_file(filepath.c_str(), pugi::parse_full);
	if (ret.status != pugi::status_ok) {
		SPDLOG_ERROR("配置文件解析失败");
		return false;
	}

	auto root = doc.child("Config");

	//设备列表
	auto devicelist_node = root.child("DeviceList");
	if (devicelist_node) {
		auto device_nodes = devicelist_node.children("Device");
		for (auto&& device_node : device_nodes) {
			auto device_info = std::make_shared<DeviceInfo>();

			device_info->IP = device_node.child_value("IP");
			device_info->Port = device_node.child("Port").text().as_uint();
			//厂家
			device_info->Manufacturer = device_node.child_value("Manufacturer");
			_devices.push_back(device_info);
		}
	}

	auto kafka_node =  root.child("Kafka");
	if(kafka_node)
	{
		_kafka_param.URI = kafka_node.child_value("URI");
		_kafka_param.Topic = kafka_node.child_value("Topic");
	}
	SPDLOG_INFO("配置文件解析完成");
	return true;
}
